package main

import (
	"bufio"
	"fmt"
	"log"
	"os"
)

func main() {
	/*
		bufio: 高效 io 读写
			buffer 缓存
			io: input/output

		将 io 包下的 Reader，Writer 对象进行包装，带缓存的包装，提高读写的效率

			func (b *Writer) Write(p []byte) (nn int, err error)
			func (b *Writer) WriteByte(c byte) error
			func (b *Writer) WriteRune(r rune) (size int, err error)
			func (b *Writer) WriteString(s string) (int,error)
	*/
	fileName := "E:/代码文件/灰太狼/羊村.txt"
	file, err := os.OpenFile(fileName, os.O_CREATE|os.O_WRONLY, os.ModePerm)
	if err != nil {
		log.Fatal(err)
	}
	defer file.Close()

	w1 := bufio.NewWriter(file)
	//n, err := w1.WriteString("喜羊羊与灰太狼")
	//fmt.Println(err)
	//fmt.Println(n)
	//w1.Flush() //刷新缓冲区，即将缓冲区的数据写到目标文件中

	for i := 1; i <= 1000; i++ {
		w1.WriteString(fmt.Sprintf("%d:喜羊羊与灰太狼", i))
	}
	w1.Flush()
}
